set nocompatible
source $VIMRUNTIME/vimrc_example.vim
" An example for a vimrc file.
"
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"	      for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"	    for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

"if has("vms")
  "set nobackup		" do not keep a backup file, use versions instead
"else
  "set backup		" keep a backup file
"endif

set nobackup
set history=50		" keep 50 lines of command line history
set ruler		" show the cursor position all the time
set showcmd		" display incomplete commands
set incsearch		" do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent		" always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
		  \ | wincmd p | diffthis
endif
source $VIMRUNTIME/mswin.vim
behave mswin
set cin
set sw=4
set ts=4
set guifont=Consolas:h14 
set nu
set et "expandtab
colo torte 
filetype plugin on

set fileencodings=utf-8,gb2312,gbk,gb18030

"set termencoding=utf-8

set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction

set makeprg=g++\ -O2\ -DLOCAL\ -o\ \"%<\"\ \"%\"
let header="#include<iostream>\nusing\ namespace\ std;\nint\ main(){\n\treturn\ 0;\n}"
"use `'` , so that '\' needn't be write as '\\'
let $lib='C:\Users\soy\Desktop\acm\template'
let $acm='C:\Users\soy\Desktop\acm'
map <F5> :w <CR> :make <CR>
autocmd Filetype c,cpp map <F6> :!"%<" <CR>
autocmd Filetype dosbatch,python map <F6> :call RunScript()<CR>
func RunScript()
    exec "w"
    exec "!start cmd /c \"%\" & pause"
endfunc
func CompileWall() 
exec "w"
exec "!start cmd /c g++ -Wall \"%\" -o \"%<.exe\" -DLOCAL & pause & \"%<.exe\" & pause"
endfunc
map <F9> :call CR()<CR> 
func CR() 
exec "w"
exec "!start cmd /c g++ % -o %<.exe & pause & %<.exe < %<.txt & pause"
endfunc
map <F10> :call CR2()<CR> 
func CR2() 
exec "w"
exec "!start cmd /c g++ \"%\" -o \"%<.exe\" -DLOCAL & pause & \"%<.exe\" & pause"
endfunc
func SetHeader()
    call append(0, "/*=============================================*\\")
    call append(1, " | Author: ziki") 
    call append(2, " | Created Time: ".strftime("%c")) 
    call append(3, " | File Name: ".expand("%")) 
    call append(4, " | Description: ") 
    call append(5, " | ") 
    call append(6, "\\*=============================================*/") 
endfunc
inoremap <F4> <C-C>:call SetHeader()<CR> 
map <F4> :call SetHeader()<CR>
inoremap <F2> <C-C>:call SetTitle()<CR> GkkO
map <F2> :call SetTitle()<CR> GkkO
func SetTitle() 
call setline(1, 	   "/*==================================================*\\")
call append(line("$"), " | Author: ziki") 
call append(line("$"), " | Created Time: ".strftime("%c")) 
call append(line("$"), " | File Name: ".expand("%")) 
call append(line("$"), " | Description: ") 
call append(line("$"), "\\*==================================================*/") 
call append(line("$"), "#include <vector>")
call append(line("$"), "#include <list>")
call append(line("$"), "#include <map>")
call append(line("$"), "#include <set>")
call append(line("$"), "#include <deque>")
call append(line("$"), "#include <queue>")
call append(line("$"), "#include <stack>")
call append(line("$"), "#include <algorithm>")
call append(line("$"), "#include <functional>")
call append(line("$"), "#include <utility>")
call append(line("$"), "#include <sstream>")
call append(line("$"), "#include <iostream>")
call append(line("$"), "#include <cstdio>")
call append(line("$"), "#include <cmath>")
call append(line("$"), "#include <cstdlib>")
call append(line("$"), "#include <cctype>")
call append(line("$"), "#include <string>")
call append(line("$"), "#include <cstring>")
call append(line("$"), "#include <string.h>")
call append(line("$"), "")
call append(line("$"), "using namespace std;")
call append(line("$"), "using namespace rel_ops;")
call append(line("$"), "")
call append(line("$"), "typedef long long int64;")
call append(line("$"), "typedef unsigned long long uint64;")
call append(line("$"), "const double pi=acos(-1.0);")
call append(line("$"), "const double eps=1e-11;")
call append(line("$"), "const int inf=0x7FFFFFFF;")
call append(line("$"), "template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}")
call append(line("$"), "template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}")
call append(line("$"), "template<class T> inline T sqr(T x){return x*x;}")
call append(line("$"), "typedef pair<int,int> PII;")
call append(line("$"), "typedef vector<int> VI;")
call append(line("$"), "typedef vector<PII> VII;")
call append(line("$"), "#define MP(A,B) make_pair(A,B)")
call append(line("$"), "#define PB(X) push_back(X)")
call append(line("$"), "#define mem(a,b) memset(a, b, sizeof(a))")
call append(line("$"), "#define clr(a) memset(a, 0, sizeof(a))")
call append(line("$"), "#define rep(i,n) for(int i=0; i<n; i++)")
call append(line("$"), "#define repit(i,v) for(typeof(v.begin()) i=v.begin(); i!=v.end(); i++)") 
call append(line("$"), "#define iter(v) typeof(v.begin())")
call append(line("$"), "#define ff first")
call append(line("$"), "#define ss second")
call append(line("$"), "#ifdef LOCAL")
call append(line("$"), "#define out(x) (cout<<#x<<\": \"<<x<<endl)")
call append(line("$"), "template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}")
call append(line("$"), "template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}")
call append(line("$"), "#else")
call append(line("$"), "#define out(...)")
call append(line("$"), "#define show(...)")
call append(line("$"), "#endif")
call append(line("$"), "int main() {")
call append(line("$"), "	return 0;")
call append(line("$"), "}")
call append(line("$"), "")  
endfunc

let g:JPYTHON_PATH = "D:/ShortCut/vim"
function! JPython(py_fname)
    let w:fname = g:JPYTHON_PATH . '/' . a:py_fname
    echo bufname(".")
    let w:cmd  = 'fp = open(r"' . bufname(".") . '", "rb");'
    let w:cmd .= 'g_text = fp.readlines();'
    let w:cmd .= 'fp.close(); del fp;'
    let w:cmd .= 'execfile("' . w:fname . '");'
    exec '%!python -c "' . escape(w:cmd, "'"") . '"'
    " 发现输出后会有^M，进 行替换用
    if has('windows')
        try
            exec '%s/r//g'
        catch
        endtry
    endif
endfunction


